#include"func.h"
char *month[12]={"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",  "Sep",
       "Oct","Nov","Dec"};
int main(int argc,char* argv[]){
    ARGS_CHECK(argc,2);
    DIR *dir = opendir(argv[1]);
    struct dirent* tmp;
    long lc;//file location
    while((tmp = readdir(dir))!=NULL){
        char path[1024]={0};
        sprintf(path,"%s%s%s",argv[1],"/",tmp->d_name);
        //sprintf是将字符串输入到数组当中,getpwuid:获取对应用户id的用户名,getgrgid:获取组的名字
        //ctime:格式化时间，字符串变为日历时间，固定形式
        //localtime:时间高级处理，可自定义形式
        struct stat statbuf;
        int ret = stat(path,&statbuf);
        ERROR_CHECK(ret,-1,"stat");
        //获取localtime时间结构体
        struct tm* time = localtime(&statbuf.st_mtime);
        //这里对文件类型进行操作
        switch (statbuf.st_mode & S_IFMT) {
           case S_IFBLK:  printf("b");break;
           case S_IFCHR:  printf("c");break;
           case S_IFDIR:  printf("d");break;
           case S_IFIFO:  printf("FIFO/pipe");break;
           case S_IFLNK:  printf("l");break;
           case S_IFREG:  printf("-");break;
           case S_IFSOCK: printf("socket ");break;
           default:       printf("unknown? ");break;
        }
        printf("%8o %3ld %8s %8s %6ld",statbuf.st_mode,
               statbuf.st_nlink,
               getpwuid(statbuf.st_uid)->pw_name,
               getgrgid(statbuf.st_gid)->gr_name,
               statbuf.st_size
               );
        printf(" %s %d %d:%d %s\n",month[time->tm_mon],time->tm_mday,time->tm_hour,time->tm_min,tmp->d_name);
    }
    seekdir(dir,lc);//set the next location
    tmp = readdir(dir);
    printf("inode_name = %s\n",tmp->d_name);
    closedir(dir);
    return 0;
}
